<?php

require '../twl-php/autoload.php';
//require '../twl-php/defaultConfig.php';

class W2MConfig {
    public static function getRobotEmail() { return 'w2m@tfolder.ru'; }
    public static function getPassword() { return 'holodilnik'; }
}

list($url, $email, $pass) = Form::bulkGetStringsAnyway('url', 'email', 'pass');


$oErrCollector = new ErrorsCollector();

if ($pass != W2MConfig::getPassword())
    $oErrCollector->addError('invalid password');

if (!preg_match('~@~', $email))
    $oErrCollector->addError('invalid email');

if (!preg_match('~^http://[a-zA-Z0-9-]{2,}\.[a-zA-Z0-9-]{2,}$~', $url))
    $oErrCollector->addError('invalid url');

$oExecutor = new TemplateExecutor('templates');

$oExecutor->assignArray(array(
    'url' => $url,
    'email' => $email,
    'pass' => $pass,
));

if ($oErrCollector->hasErrors()) {

    $oExecutor->assign('error', $oErrCollector->getErrorsAsHtmlList());

} else {

    $sPageContent = WebHorse::singlePageRequest($url)->getContent();

    $oTempFile = new TemporaryFile();
    $oTempFile->append($sPageContent);

    $subj = 'test';
    Mail::sendWithFiles(W2MConfig::getRobotEmail(), $email, $subj, 'text', array($oTempFile->getPath()));

    $oExecutor->assign('msg', HumanFormat::filesize(strlen($sPageContent)) . ' data sent');
}

$oExecutor->exec('index.php');

?>